package com.durian.city.controller;

import com.durian.city.api.domain.City;
import com.durian.city.service.ICityService;
import com.durian.common.core.domain.R;
import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 城市Controller
 *
 * @author durian
 * @date 2022-06-25
 */
@RestController
@RequestMapping("/city")
public class CityController extends BaseController
{
    @Autowired
    private ICityService cityService;

    /**
     * 查询城市列表
     */
    @RequiresPermissions("city:city:list")
    @GetMapping("/list")
    public R<List<City>> list(City city)
    {
        List<City> list = cityService.selectCityList(city);
        return R.ok(list);
    }

    /**
     * 导出城市列表
     */
    @RequiresPermissions("city:city:export")
    @Log(title = "城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, City city)
    {
        List<City> list = cityService.selectCityList(city);
        ExcelUtil<City> util = new ExcelUtil<City>(City.class);
        util.exportExcel(response, list, "城市数据");
    }

}
